package com.rpcfx.api.spi;

import com.rpcfx.api.LoadBalancer;

import java.util.List;
import java.util.Random;

/**
 * @ProjectName: learning
 * @Package: com.rpcfx.api.spi
 * @ClassName: RandomLoadBalancer
 * @Description:
 * @Date: 2021/11/12 11:02 上午
 * @Version: 1.0
 */
public class RandomLoadBalancer implements LoadBalancer {
    @Override
    public String select(List<String> urls) {
        if (urls.size() == 1) {
            return urls.get(0);
        }
        return urls.get(new Random().nextInt(urls.size()));
    }
}
